﻿using System;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace WebApplication1.InfoManagement
{
    public partial class ToolRoomManagement : System.Web.UI.Page
    {
        private ToolRoom t;

        public ToolRoomManagement()
        {
            t = new ToolRoom();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindToolRoom();
            }
        }

        private void BindToolRoom()
        {
            this.GridView1.DataSource = t.LoadEntities();
            this.GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            BindToolRoom();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            BindToolRoom();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            ToolRoomInfo tinfo = new ToolRoomInfo();
            tinfo.ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
            tinfo.RoomName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim().ToString();

            t.Update(tinfo);
            GridView1.EditIndex = -1;
            BindToolRoom();
        }
    }
}
